package com.kyang.musiconline.controller;

import com.kyang.musiconline.model.ResponseData;
import com.kyang.musiconline.model.Vinyl;
import com.kyang.musiconline.service.VinylService;
import com.kyang.musiconline.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author kyang
 */
@RestController
@RequestMapping("/music")
@CrossOrigin
public class VinylController {
    @Autowired
    private VinylService vinylService;

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ResponseData addMusic(Vinyl vinyl) {
        vinyl.setMusicUser(JwtUtil.getCurrentUserId());
        boolean isSuccess = vinylService.addMusic(vinyl);
        return new ResponseData(200, isSuccess, "success", "");
    }

    @RequestMapping(value = "/del", method = RequestMethod.POST)
    public ResponseData delMusic(String vinylId) {
        boolean isSuccess = vinylService.delMusic(vinylId);
        return new ResponseData(200, isSuccess, "success", "");
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseData updateMusic(Vinyl vinyl) {
        boolean isSuccess = vinylService.updateMusic(vinyl);
        return new ResponseData(200, isSuccess, "success", "");
    }

    @RequestMapping(value = "/info", method = RequestMethod.POST)
    public ResponseData getMusicInfoById(String vinylId) {
        Vinyl vinyl = vinylService.getMusicInfo(vinylId);
        return new ResponseData(200, true, "success", vinyl);
    }

}
